package com.xizi.秋招笔试.qixinan;

import java.util.Comparator;
import java.util.PriorityQueue;

/**
 * @author xizizzz
 * @description: TODO
 * @date 2021-8-23下午 03:45
 */
public class Test2 {
    public static void main(String[] args) {

    }

    public int getMinLength(int[][] pearls) {
        PriorityQueue<Integer[]> queue = new PriorityQueue<Integer[]>(new Comparator<Integer[]>() {
            @Override
            public int compare(Integer[] o1, Integer[] o2) {
                if ((o1[0] + o1[1]) == (o2[0] + o2[1])) {
                    if (o1[0] == o2[0]) {
                        return o1[1] - o2[1];
                    } else {
                        return o1[0] - o2[0];
                    }
                } else if ((o1[0] + o1[1]) < (o2[0] + o2[1])) {
                    return (o1[0] + o1[1]) - (o2[0] + o2[1]);
                } else {
                    return (o2[0] + o2[1]) - (o1[0] + o1[1]);
                }
            }
        });
        for (int i = 0; i < pearls.length; i++) {
            queue.add(new Integer[]{pearls[i][0], pearls[i][1]});
        }
        int res = 0;
        if (!queue.isEmpty()) {
            Integer[] poll1 = queue.poll();
            Integer[] poll2 = queue.poll();
            Integer[] poll3 = queue.poll();
            final int res1 = Math.abs(poll1[0] - poll2[0]) + Math.abs(poll1[1] - poll2[1]);
            final int res2 = Math.abs(poll2[0] - poll3[0]) + Math.abs(poll2[1] - poll3[1]);
            res = res1 + res2;
        }
        aaa();
        int b = a;
        return res;
    }

    static Integer a = 1;

    public static void aaa() {

    }
}
